package com.fs.service.Impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.mapper.WhTransferMapper;
import com.fs.pojo.WhTransfer;
import com.fs.pojo.WhWarehouse;
import com.fs.pojo.WhWarehousing;
import com.fs.service.WhTransferService;
import com.fs.vo.Condition;
import org.apache.coyote.http11.filters.IdentityOutputFilter;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @author: qiji
 * @Date 2024-10-12 09:06
 * @description:
 */
@Service
public class WhTransferServiceImpl implements WhTransferService {


    @Resource
    private WhTransferMapper whTransferMapper;

    /**
     * 添加调拨单
     *
     * @param whTransfer 调拨单模型
     * @return
     */
    @Override
    public Integer addWhTransfer(WhTransfer whTransfer) {
        return whTransferMapper.insert(whTransfer);
    }

    /**
     * 删除调拨单
     * @param transferId
     * @return
     */
    @Override
    public Integer deleteTransfer(int transferId) {
        return whTransferMapper.deleteById(transferId);
    }

    /**
     * 更新调拨单
     * @param whTransfer
     * @return
     */
    @Override
    public Integer updateTransfer(WhTransfer whTransfer) {
        return whTransferMapper.updateById(whTransfer);
    }

    @Override
    public Page<WhTransfer> selectPage(Condition<WhTransfer> condition) {

        Page<WhTransfer> page = new Page<>(condition.getPage(),condition.getCount());
        //构建条件构造器
        LambdaQueryWrapper<WhTransfer> wrapper = new LambdaQueryWrapper<>();
        WhTransfer whTransfer=condition.getSearch();
        if (Objects.nonNull(whTransfer)){
            //供应商姓名模糊查询条件
            wrapper.like(whTransfer.getDestinationWarehouseId()!=null,WhTransfer::getDestinationWarehouseId,whTransfer.getDestinationWarehouseId())
                    //编号查询
                    .eq(whTransfer.getCreatedBy()!=null,WhTransfer::getCreatedBy,whTransfer.getCreatedBy())

                    .eq(whTransfer.getTransferStatus()!=null,WhTransfer::getTransferStatus,whTransfer.getTransferStatus());
        }
        return whTransferMapper.selectPage(page,wrapper);
    }

    @Override
    public WhTransfer queryTransferById(Integer id) {
        return whTransferMapper.selectById(id);
    }


    /**
     * 查询调拨单
     * @param
     * @return
     */
    @Override
    public List<WhTransfer> queryAll() {
        return whTransferMapper.selectList(null);
    }
}
